<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<script src="/admin/xadmin/lib/layui/upload.js" charset="utf-8"></script>

<body>
    <div class="x-body">
        <form class="layui-form" lay-filter="formAjax">
            <div class="layui-form-item" style="display: flex;">
                <label class="layui-form-label">
                    <span class="x-red">*</span>合作方
                </label>
                <div id="pMenu" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-form-item" style="display: flex;">
                <label class="layui-form-label">
                    <span class="x-red">*</span>选择短剧
                </label>
                <div id="pVideo" style="width: 100%;flex: 1;"></div>
            </div>

            <input type="hidden" name="id" id="id" value="" />
            <input type="hidden" name="video_name" id="video_name" value="" />
            <input type="hidden" name="admin_name" id="admin_name" value="" />
            <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;" />

        </form>
    </div>
    <script>
        let params = {
            addUrl: '/admin/partnersNew/editTheCooperater',
            editUrl: '/admin/partnersNew/editTheCooperater',
            detailUrl: '/admin/partnersNew/cooperaterDetail',
        }
        //form数据自动根据字段展示
        form_ajax(params)

        let type = GetQueryString('type')
        /* 合作方选择 */
        let xmSelectAdminOption = {
            url: '/admin/partnersNew/selectCooperaterList?type=' + type,
            initValue: '',//初始值
            el: '#pMenu',
            pageSize: 5,
            name: 'admin_id',
            radio: true,
            clickClose: true,
            disabled: type == 1 ? true : false,
            label: {
                type: 'text'
            },
            onFn: function (data) {
                $('#admin_name').val(data.arr[0].name)
            },
        }
        let xmSelectVideoOption = {
            url: '/admin/partnersNew/selectVideoNameList',
            initValue: '',//初始值
            el: '#pVideo',
            pageSize: 5,
            name: 'video_id',
            radio: false,
            clickClose: false,
            label: {
                type: 'text'
            },
            onFn: function (data) {
                console.log(data)
                let str = '';
                $.each(data.arr, function (index, value) {
                    // 在这里执行对每个元素的操作
                    str = str == '' ? value.name : str + ',' + value.name
                });
                $('#video_name').val(str)
            },
        }
        let id = GetQueryString('id')
        if (id) {
            Ajax(params.detailUrl, { id }).then(result => {
                xmSelectAdminOption.initValue = [result.data.admin_id]
                xmSelectVideoOption.initValue = result.data.video_id_arr
                xmSelectA(xmSelectAdminOption)
                xmSelectA(xmSelectVideoOption)
            });
        } else {
            xmSelectA(xmSelectAdminOption)
            xmSelectA(xmSelectVideoOption)
        }
    </script>
</body>

</html>